﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.Office.Server.Search.WebControls;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Xml.Serialization;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Administration;

namespace SPSearchAsYouTypeWP.SearchBoxAsYouType
{
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
    [ComVisible(false)]
    [ScriptDescriptorComponentType("Srch.SearchBoxAsYouType")]
    [SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel = true)]
    [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
    [XmlRoot(Namespace = "urn:schemas-microsoft-com:SearchBoxAsYouType")]
    public class SearchBoxAsYouType : SearchBoxScriptWebPart
    {
        protected override void RenderWebPart(HtmlTextWriter output)
        {
            base.RenderWebPart(output);
            string str2=string.Concat(base.CsrContainerId, "_sbox");
            string[] strArraysSearch = new string[] { "EnsureScriptFunc('Search.ClientControls.js', 'Srch.U', function() {$find('", SPHttpUtility.EcmaScriptStringLiteralEncode(base.CsrContainerId), "').search($get('", SPHttpUtility.EcmaScriptStringLiteralEncode(str2), "').value + '*');})" };
            
            output.Write("<script>$('#{0}').keyup(function(event){1})</script>",str2,string.Concat(strArraysSearch));
            

        }
    }
}